﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Webservice.Repository.Base;
using WebService;
using WebService.IRepository;
using WebService.IRepository.Work;

namespace Webservice.Repository
{
    public class MenuRepository : BaseRepository<Sys_Menu>, IMenuRepository
    {
        public MenuRepository(IWork work) : base(work)
        {

        }

        /// <summary>
        /// 根据用户查找菜单
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <returns>菜单列表</returns>
        public async Task<List<Sys_Menu>> FindByUser(string userName)
        {
            return await QuerySql($"SELECT DISTINCT (D.id),D.parent_id,D.`name`,D.icon,D.order_num,D.type,D.url,D.perms,D.del_flag FROM sys_user A LEFT JOIN sys_user_role B ON A.id = B.user_id LEFT JOIN sys_role_menu C ON B.role_id = C.role_id LEFT JOIN sys_menu D ON C.menu_id = D.id WHERE A.`name` = '{userName}' ORDER BY parent_id ASC");
        }
    }
}
